package dao

import (
	"oidc/model"
)

var count int

var ClientDB map[int]model.Client //id-

func init() {
	count = 0
	ClientDB = make(map[int]model.Client)
}

func AddClient(client model.Client) {
	ClientDB[count] = client
	count++
}

func IFClientIDRight(clientRe model.Client) bool { //不判断ClientSecret
	status := false
	for _, val := range ClientDB {
		if val.ClientID == clientRe.ClientID {
			if val.RedirectUrl == clientRe.RedirectUrl {
				status = true
			}
		}
	}
	return status
}

func IFClientSecretRight(clientRe model.Client) bool { //判断ClientSecret
	status := false
	for _, val := range ClientDB {
		if val.ClientID == clientRe.ClientID {
			if val.RedirectUrl == clientRe.RedirectUrl && val.ClientSecret == clientRe.ClientSecret {
				status = true
			}
		}
	}
	return status
}
